package leetcode.weekly.week298;

//Solution1Test
public class Solution1 {
	// Solution1Test
	public String greatestLetter(String s) {
		char[] cs = s.toCharArray();
		int len = cs.length;
		boolean[] hash = new boolean[26];
		for (int i = 0; i < len; i++) {
			char cur = cs[i];
			if (cur >= 'a' && cur <= 'z') {
				int index = cur - 'a';
				hash[index] = true;
			}
		}
		int ans = -1;
		for (int i = 0; i < len; i++) {
			char cur = cs[i];
			if (cur >= 'A' && cur <= 'Z') {
				int index = cur - 'A';
				if (hash[index] && index > ans) {
					ans = index;
				}
			}
		}
		return ans == -1 ? "" : String.valueOf((char) (ans + 'A'));
	}

}
